package com.vcredit.creditcat.framework.util;

import java.lang.reflect.Field;
import java.util.Date;

import org.springframework.util.ReflectionUtils;

import com.vcredit.creditcat.util.ConcurrentDateUtil;

public class BeanUtil {
	public static String toString(Object obj){
		StringBuffer buf = new StringBuffer();
		Field[] fields = obj.getClass().getDeclaredFields();
		for(Field f:fields){
			ReflectionUtils.makeAccessible(f);
			if(f.getType().equals(Integer.class)||f.getType().equals(Long.class)||f.getType().equals(String.class)||f.getType().equals(Short.class)||
					f.getType().equals(int.class)||f.getType().equals(long.class)||f.getType().equals(byte.class)||f.getType().equals(short.class)){
				buf.append("/").append(f.getName()).append(":").append(ReflectionUtils.getField(f, obj));
			}else if(f.getType().equals(Date.class)){
				buf.append("/").append(f.getName()).append(":").append(ConcurrentDateUtil.formatDateTime((Date)ReflectionUtils.getField(f, obj)));
			}
			
		}
		return buf.toString();
	}
}
